package com.tjec.project.projectWorkbench.service.impl;

import com.tjec.common.utils.StringUtils;
import com.tjec.project.projectWorkbench.domain.BmsProjectFocus;
import com.tjec.project.projectWorkbench.mapper.BmsProjectFocusMapper;
import com.tjec.project.projectWorkbench.service.IBmsProjectFocusService;
import com.tjec.project.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * 关注的项目 Service业务层处理
 *
 * @author cjj
 * @date 2020-05-25
 */
@Service
public class BmsProjectFocusServiceImpl implements IBmsProjectFocusService {
    @Autowired
    private BmsProjectFocusMapper bmsProjectFocusMapper;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询关注的项目
     *
     * @param guid 关注的项目 ID
     * @return 关注的项目
     */
    @Override
    public BmsProjectFocus selectBmsProjectFocusByGuid(String guid) {
        return bmsProjectFocusMapper.selectBmsProjectFocusByGuid(guid);
    }

    /**
     * 查询关注的项目 列表
     *
     * @param bmsProjectFocus 关注的项目
     * @return 关注的项目
     */
    @Override
    public Set<BmsProjectFocus> selectBmsProjectFocusList(BmsProjectFocus bmsProjectFocus) {
        if(StringUtils.isNotBlank(bmsProjectFocus.getUserId())){
            String projectLeaderNo = sysUserService.findProjectLeaderNoByUserGuid(bmsProjectFocus.getUserId());
            if(StringUtils.isNotBlank(projectLeaderNo)){
                bmsProjectFocus.setProjectLeaderNo(projectLeaderNo);
            }
        }
        return bmsProjectFocusMapper.selectBmsProjectFocusList(bmsProjectFocus);
    }

    /**
     * 新增关注的项目
     *
     * @param bmsProjectFocus 关注的项目
     * @return 结果
     */
    @Override
    public int insertBmsProjectFocus(BmsProjectFocus bmsProjectFocus) {
        if (null == bmsProjectFocus.getGuid() || ("").equals(bmsProjectFocus.getGuid())) {
            bmsProjectFocus.setGuid(UUID.randomUUID().toString());
        }
        return bmsProjectFocusMapper.insertBmsProjectFocus(bmsProjectFocus);
    }

    /**
     * 修改关注的项目
     *
     * @param bmsProjectFocus 关注的项目
     * @return 结果
     */
    @Override
    public int updateBmsProjectFocus(BmsProjectFocus bmsProjectFocus) {
        return bmsProjectFocusMapper.updateBmsProjectFocus(bmsProjectFocus);
    }

    /**
     * 批量删除关注的项目
     *
     * @param guids 需要删除的关注的项目 ID
     * @return 结果
     */
    @Override
    public int deleteBmsProjectFocusByGuids(String[] guids) {
        return bmsProjectFocusMapper.deleteBmsProjectFocusByGuids(guids);
    }

    /**
     * 删除关注的项目 信息
     *
     * @param guid 关注的项目 ID
     * @return 结果
     */
    @Override
    public int deleteBmsProjectFocusByGuid(String guid) {
        return bmsProjectFocusMapper.deleteBmsProjectFocusByGuid(guid);
    }

    @Override
    public int deleteBmsProjectFocusByUserAndProject(String userId, String projectId) {
        return bmsProjectFocusMapper.deleteBmsProjectFocusByUserAndProject(userId, projectId);
    }
}
